<?php
/**
 * Created by PhpStorm.
 * User: moonlight
 * Date: 2015/6/3
 * Time: 17:38
 */

namespace Home\Model;


use Think\Model;

class GoodsModel extends Model{

    //添加goods
    public function addGoods($goodsData){
        $data   =   array(          //避免表单字段问题 重新赋值
            'blog_id'   =>  $goodsData['blog_id'],
            'goods_name'    =>  $goodsData['goods_name'],
            'goods_date'    =>  $goodsData['goods_date'],
            'goods_place'   =>  $goodsData['goods_place'],
            'goods_description' =>  $goodsData['goods_description'],
            'goods_picture' =>  $goodsData['goods_picture'],
        );
        if($this->data($data)->add()){
            return ture;    //插入成功
        }
        return  false;  //插入失败
    }

    /**
     * 通过blog_id获取good信息
     * @param $blog_id
     * @return array
     */
    public function getGoodsData($blog_id){
        if(empty($blog_id)){
            return 'id为空';    //想到个问题，如果查询结果也为空呢？貌似没有对这个做处理
        }else{
            $condition['blog_id']   =   $blog_id;
            $result =   $this->where($condition)->find();
            if($result){
                return $result;
            }
            return false;
        }
        return;
    }
}